{% load static %}
<input id="file-selector" type="file">
<script src="{% static 'js/cos-js-sdk-v5.min.js' %}"></script>
<script>
var Bucket = '18361077805-1603095459-1303881619';
var Region = 'ap-nanjing';     /* 存储桶所在地域，必须字段 */

// 初始化实例
var cos = new COS({
    getAuthorization: function (options, callback) {
        // 异步获取临时密钥
        $.get('{% url 'app01:cos_upload' %}', {
            bucket: options.Bucket,
            region: options.Region,
        }, function (data) {
            var credentials = data && data.credentials;
            if (!data || !credentials) return console.error('credentials invalid');
            callback({
                TmpSecretId: credentials.tmpSecretId,
                TmpSecretKey: credentials.tmpSecretKey,
                XCosSecurityToken: credentials.sessionToken,
                // 建议返回服务器时间作为签名的开始时间，避免用户浏览器本地时间偏差过大导致签名错误
                StartTime: data.startTime, // 时间戳，单位秒，如：1580000000
                ExpiredTime: data.expiredTime, // 时间戳，单位秒，如：1580000900
            });
        });
    }
});

// 接下来可以通过 cos 实例调用 COS 请求。
// TODO

</script>











{#<!DOCTYPE html>#}
{#<html lang="en">#}
{#<head>#}
{#    <meta charset="UTF-8">#}
{#    <title>Cos File</title>#}
{# <link rel="stylesheet" href="{% static 'plugin/bootstrap/css/bootstrap.min.css' %}">#}
{##}
{##}
{##}
{#    <link rel="stylesheet" href="{% static 'plugin/font-awesome/css/font-awesome.min.css' %}">#}
{##}
{#</head>#}
{#<body>#}
{# <div   style="width: 600px;height: 400px;">#}
{#        <button  >#}
{##}
{##}
{#            <a class="btn btn-primary " id="cos_upload" href="#">上传文件</a>#}
{##}
{#        </button>#}
{#    </div>#}
{##}
{##}
{# <script src="{% static 'js/jquery.min.js' %}"></script>#}
{# <script src="{% static 'plugin/bootstrap/js/bootstrap.min.js' %}"></script>#}
{# <script src="{% static 'js/cos-js-sdk-v5.min.js' %}"></script>#}
{#<script>#}
{#var COS = require('cos-js-sdk-v5');#}
{##}
{# $(function () {#}
{#    $('#cos_upload').click(function ());#}
{# });#}
{##}
{##}
{#var cos = new COS({#}
{#    // 必选参数#}
{#    getAuthorization: function (options, callback) {#}
{#        // 服务端 JS 和 PHP 例子：https://github.com/tencentyun/cos-js-sdk-v5/blob/master/server/#}
{#        // 服务端其他语言参考 COS STS SDK ：https://github.com/tencentyun/qcloud-cos-sts-sdk#}
{#        // STS 详细文档指引看：https://cloud.tencent.com/document/product/436/14048#}
{#        $.get('{% url 'app01:cos_upload' %}', {#}
{#            // 可从 options 取需要的参数#}
{#        }, function (data) {#}
{#            var credentials = data && data.credentials;#}
{#            if (!data || !credentials) return console.error('credentials invalid');#}
{#            callback({#}
{#                TmpSecretId: credentials.tmpSecretId,#}
{#                TmpSecretKey: credentials.tmpSecretKey,#}
{#                XCosSecurityToken: credentials.sessionToken,#}
{#                // 建议返回服务器时间作为签名的开始时间，避免用户浏览器本地时间偏差过大导致签名错误#}
{#                StartTime: data.startTime, // 时间戳，单位秒，如：1580000000#}
{#                ExpiredTime: data.expiredTime, // 时间戳，单位秒，如：1580000900#}
{#            });#}
{#        });#}
{#    }#}
{#});#}
{##}
{##}
{##}
{##}
{##}
{##}
{##}
    {#$(function (){#}
    {#    cosFileUpload();#}
    {##}
{##}
    {#function cosFileUpload(){#}
    {##}
    {#    $('#cos_upload').click(function (){#}
    {#        $.ajax({#}
    {#            url:'{% url 'app01:cos_upload' %}',#}
    {#            type: "POST",#}
    {#            data: {'Token_request':true,'Cos_url':'' },//包含表中的呀unsu 和 csrf_token?#}
    {#            dataType: 'JSON',#}
    {#            success: function (res){#}
    {#                if (res.status){#}
    {#                    console.log('upload_success')#}
    {#                    console.log(res.data.s_id)#}
    {#                    var tempToken =#}
    {#                    CosSend();#}
    {#                }#}
    {##}
    {##}
    {#            }#}
    {#        })#}
    {#    })#}
{##}
{#</script>#}
{##}
{##}
{##}
{##}
{#</body>#}
{#</html>#}